package ten.test_10_25;

import java.util.Scanner;

public class TestMain1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            int max = Math.max(n, m);
            int min = Math.min(n, m);
            int count = 0;
            while (max != 0 || min != 0) {
                while (max >= 2*min) {
                    min *= 2;
                    count++;
                }
                min--;
                max--;
                count++;
            }
            System.out.println(count);
        }
    }
}
